﻿using System;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using WcfService1.DTO;
using System.Linq;

namespace Lib.Converter
{
    public class CustomerConverter : IValueConverter
    {
        #region IValueConverter Members

        object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (value != null)
            {
                return ((dynamic)value).CustomerName + ":" + ((dynamic)value).CustomerId;
            }
            else
            {
                return string.Empty;
            }
        }

        object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            
            if (value == null) return null;
             var text = value.ToString().Split(new string[] {":"},StringSplitOptions.None);
            return new CustomerDTO() {CustomerId = text.LastOrDefault(), CustomerName = text.FirstOrDefault()};
        }

        #endregion
    }
}
